/*
 * Copyright © 2011 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.classes;

import javax.microedition.lcdui.*;
import com.senseforce.midlets.PhoneBook;

/**
 *
 * @author jcccn
 * @site http://www.senseforce.com/
 */
public class PhoneBookWelcomeCanvas extends Canvas implements CommandListener {

	private PhoneBook midlet = null;
	private Command exitCommand = new Command("Exit", Command.EXIT, 0);
	private Command contactsCommand = new Command("Contacts", Command.SCREEN, 0);
	private Image welcomeImage = null;

	public PhoneBookWelcomeCanvas(PhoneBook midlet) {
		this.midlet = midlet;
		setCommandListener(this);
		addCommand(exitCommand);
		addCommand(contactsCommand);
		try {
			welcomeImage = Image.createImage(PhoneBookConfig.img_path_welcome);
		} catch(Exception ex) {
			
		}
	}

	protected void paint(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(0, 0, 255);
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		g.drawString("Welcome to Phone Book !", getWidth()/2, 50, Graphics.HCENTER | Graphics.TOP);
		g.drawImage(welcomeImage, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
	}
	
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {
			try {
				midlet.destroyApp(true);
			} catch(Exception ex) {
			
			}
			midlet.notifyDestroyed();
		}
		else if (c == contactsCommand) {
			midlet.changeForm(PhoneBookConfig.FORMTYPE_PHONELIST);
		}
	}

}
